package slap.mvc.result;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import slap.Slap;
import slap.exception.UnexpectedException;
import slap.http.Request;
import slap.http.Response;
import slap.http.StatusCode;
import slap.util.MimeTypes;

/**
 * 404 not found
 */
public class NotFound extends Result {
	protected static final Logger logger = LoggerFactory.getLogger(NotFound.class);
    /**
     * @param why a description of the problem
     */
    public NotFound(String why) {
        super(why);
    }

    /**
     * @param method routed method
     * @param path  routed path 
     */
    public NotFound(String method, String path) {
        super(method + " " + path);
    }

    public void apply(Request request, Response response) {
    	logger.info("Can not find reqired resource: [{}]", this.getMessage());
        response.status = StatusCode.NOT_FOUND;
        String errorHtml = "Not found: " + this.getMessage();
        try {
            response.out.write(errorHtml.getBytes("utf-8"));
        } catch (Exception e) {
            throw new UnexpectedException(e);
        }
    }
}
